<?php

namespace Common\Model;
use Think\Model\RelationModel;
class Orgnizer_grouptestModel extends RelationModel {

    protected $_link = array(
        'user_quizlist'=>array(
            'mapping_type' => self::HAS_MANY,
            'class_name'    =>'Orgnizer_userquizlist',
            'foreign_key' => 'testgroup_id'
        ),
    );


    public function getUserQuizList($title)
    {
        $data = $this->where(['orgnizer_grouptest.title'=>$title])
            ->join("orgnizer_userquizlist  on orgnizer_grouptest.testgroup_id = orgnizer_userquizlist.testgroup_id")
            ->join("users on users.uid = orgnizer_userquizlist.uid")
            ->join("orgnizeruserclass on orgnizeruserclass.uid = orgnizer_userquizlist.uid")
            ->select();

        foreach($data as &$d){
            unset($d['password']);
            $d['class'] = convertClassJson($d['class']);
            $d['quiz_list_name'] = convertQuizListJson($d['quiz_list']);

        }


        return $data;
    }



}